﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Data;


public partial class WebCommon_VerifyCircruitForUserPlanDisplay : System.Web.UI.Page
{
    SystemLog dllSystemLog = new SystemLog();
    VerifyCircuitManager dllVerifyCircuit = new VerifyCircuitManager();
    UserInfoManager dllUserInfoManager = new UserInfoManager();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            getVerifyCircruit();
            getSystemLog();
        }
    }

    /// <summary>
    /// 得到指定计划的流程和对应的日志
    /// </summary>
    void getVerifyCircruit()
    {
        int _planId = Utility.HttpHelp.getParamsInt("PlanId");
        int _planType = Utility.HttpHelp.getParamsInt("PlanType");
        object[] _value = new object[1];
        _value[0] = _planId;
        DataTable _planTable = new DataTable();
        DataTable _systemLog = new DataTable();
        if (_planType == 4)//员工月计划类型
        {
            BLL.UserPlanMonth dllUserPlanMonth = new UserPlanMonth();
            _planTable = dllUserPlanMonth.get(UserPlanMonth.field.MonthPlanId.ToString(), _value);
            object[] _valueQuarter = new object[2];
            _valueQuarter[0] = _planId;
            _valueQuarter[1] = _planType;
            _systemLog = dllSystemLog.getUserMonthPlanTrueLog(_valueQuarter);
        }
        if (_planType == 5)//员工周计划类型
        {
            BLL.UserPlanWeek dllUserPlanWeek = new UserPlanWeek();
            _planTable = dllUserPlanWeek.get(UserPlanWeek.field.WeekPlanId.ToString(), _value);
            object[] _valueMonth = new object[2];
            _valueMonth[0] = _planId;
            _valueMonth[1] = _planType;
            _systemLog = dllSystemLog.getUserWeekPlanTrueLog(_valueMonth);
        }
       

        bindTable(_planTable, _systemLog);

    }


    /// <summary>
    /// 得到该计划对应的日志
    /// </summary>
    void getSystemLog()
    {
        object[] _value = new object[2];
        _value[0] = Utility.HttpHelp.getParamsInt("PlanId");
        _value[1] = Utility.HttpHelp.getParamsInt("PlanType");
        DataTable _systemLog = dllSystemLog.getSystemLog(_value);
        this.gdvVircuit.DataSource = _systemLog;
        this.gdvVircuit.DataBind();
    }


    /// <summary>
    /// 
    /// </summary>
    /// <param name="_planTable"></param>
    void bindTable(DataTable _planTable, DataTable _systemLog)
    {
        //创建图像行
        TableRow _trVerifyImage = new TableRow();
        //创建姓名行
        TableRow _trVerifyPeople = new TableRow();
        //创建时间行
        TableRow trTime = new TableRow();

        #region 绑定发起人
        //根据计划id查询发起人
        string _sponsorPeople = "";
        object[] _sponsor = new object[1];
        _sponsor[0] = _planTable.Rows[0]["Sponsor"].ToString();
        DataTable _userinfo = dllUserInfoManager.getSponsor(_sponsor);
        if (_userinfo.Rows.Count > 0)
        {
            _sponsorPeople = _userinfo.Rows[0]["RealName"].ToString();
        }
        else
        {
            Utility.Error.RedirectErrorPage("数据读取错误，请重试！");
        }
        //定义发起人图像
        TableCell _tcSponsorPeopleImage = new TableCell();
        Image _imgSponsorPeople = new Image();
        //定义发起人时间
        TableCell _tcSponsorTime = new TableCell();
        Label _lblSponsorTime = new Label();
        if (_systemLog.Rows.Count > 0)
        {
            _lblSponsorTime.Text = _systemLog.Rows[0]["TimeDate"].ToString().Replace(" ", "<br>");
        }
        else
        {
            _lblSponsorTime.Text = "";
        }
        if (_planTable.Rows[0]["PlanSendState"].ToString() == "0")
        {
            _imgSponsorPeople.ImageUrl = "../images/verifyPeople.gif";
        }
        else
        {
            _imgSponsorPeople.ImageUrl = "../images/verifyPeople1.gif";
        }
        //绑定发起人图像到table
        _tcSponsorPeopleImage.Controls.Add(_imgSponsorPeople);
        _trVerifyImage.Cells.Add(_tcSponsorPeopleImage);
        //绑定发起人时间到table
        _tcSponsorTime.Controls.Add(_lblSponsorTime);
        trTime.Controls.Add(_tcSponsorTime);
        //创建箭头单元格
        _tcSponsorPeopleImage = new TableCell();
        Label _lbl = new Label();
        _lbl.Text = "—>";
        _tcSponsorPeopleImage.Controls.Add(_lbl);
        _trVerifyImage.Cells.Add(_tcSponsorPeopleImage);

        //绑定发起人名称到ｔａｂｌｅ
        TableCell _tcSponsorPeople = new TableCell();
        Label _lblSponsorPeople = new Label();
        _lblSponsorPeople.Text = _sponsorPeople;
        _tcSponsorPeople.Controls.Add(_lblSponsorPeople);
        _trVerifyPeople.Cells.Add(_tcSponsorPeople);

        //创建发起人后箭头单元格
        _tcSponsorPeople = new TableCell();
        _lbl = new Label();
        _lbl.Text = "—>";
        _lbl.Visible = false;
        _tcSponsorPeople.Controls.Add(_lbl);
        _trVerifyPeople.Cells.Add(_tcSponsorPeople);
        //创建发起人时间后空格
        _tcSponsorTime = new TableCell();
        trTime.Controls.Add(_tcSponsorTime);

        #endregion

        #region 绑定评估人
        //根据计划id查询评估人
        string _evaluatePeople = _planTable.Rows[0]["EvaluatePeople"].ToString();
        //绑定评估人图像到table
        TableCell _tcEvaluatePeopleImage = new TableCell();
        Image _imgEvaluatePeople = new Image();
        if (Convert.ToInt32(_planTable.Rows[0]["PlanSendState"].ToString()) >= 2)
        {
            _imgEvaluatePeople.ImageUrl = "../images/verifyPeople1.gif";
        }
        else
        {
            _imgEvaluatePeople.ImageUrl = "../images/verifyPeople.gif";
        }
        _tcEvaluatePeopleImage.Controls.Add(_imgEvaluatePeople);
        _trVerifyImage.Cells.Add(_tcEvaluatePeopleImage);

        //绑定评估人名称到ｔａｂｌｅ
        TableCell _tcEvaluatePeople = new TableCell();
        Label _lblEvaluatePeople = new Label();
        _lblEvaluatePeople.Text = _evaluatePeople;
        _tcEvaluatePeople.Controls.Add(_lblEvaluatePeople);
        _trVerifyPeople.Cells.Add(_tcEvaluatePeople);


        //绑定评估人时间
        TableCell _tcEvaluateTime = new TableCell();
        Label _lblEvaluateTime = new Label();
        if (_systemLog.Rows.Count > 1)
        {
            _lblEvaluateTime.Text = _systemLog.Rows[1]["TimeDate"].ToString().Replace(" ", "<br>");
        }
        else
        {
            _lblEvaluateTime.Text = "";
        }

        _tcEvaluateTime.Controls.Add(_lblEvaluateTime);
        trTime.Cells.Add(_tcEvaluateTime);

        //绑定评估人后箭头
        _tcEvaluatePeopleImage = new TableCell();
        _lblEvaluatePeople = new Label();
        _lblEvaluatePeople.Text = "—>";
        _tcEvaluatePeopleImage.Controls.Add(_lblEvaluatePeople);
        _trVerifyImage.Cells.Add(_tcEvaluatePeopleImage);

        //绑定空表格
        _tcEvaluatePeople = new TableCell();
        _lblEvaluatePeople = new Label();
        _lblEvaluatePeople.Text = "";
        _tcEvaluatePeople.Controls.Add(_lblEvaluatePeople);
        _trVerifyPeople.Cells.Add(_tcEvaluatePeople);


        #endregion

        #region  绑定流程人员
        //根据计划id 查询流程id并得到流程数
        int _verifyCircuitId = Convert.ToInt32(_planTable.Rows[0]["VerifyCircuitId"].ToString());
        object[] _value = new object[1];
        _value[0] = _verifyCircuitId;
        DataTable _verifyCircuit = dllVerifyCircuit.get(VerifyCircuitManager.field.VerifyCircuitId.ToString(), _value);


        for (int i = 0; i < _verifyCircuit.Rows.Count; i++)
        {


        }
        this.tableVerify.Rows.Add(_trVerifyImage);
        this.tableVerify.Rows.Add(_trVerifyPeople);
        this.tableVerify.Rows.Add(trTime);
        for (int j = 0; j < this.tableVerify.Rows.Count; j++)
        {
            this.tableVerify.Rows[j].HorizontalAlign = HorizontalAlign.Center;
        }
        #endregion


        #region 绑定评估人
        //根据计划id查询评估人
        string _evaluatePeople2 = _planTable.Rows[0]["EvaluatePeople"].ToString();
        //绑定评估人图像到table
        TableCell _tcEvaluatePeopleImage2 = new TableCell();
        Image _imgEvaluatePeople2 = new Image();
        if (Convert.ToInt32(_planTable.Rows[0]["PlanSendState"].ToString()) > 3)
        {
            _imgEvaluatePeople2.ImageUrl = "../images/verifyPeople1.gif";
        }
        else
        {
            _imgEvaluatePeople2.ImageUrl = "../images/verifyPeople.gif";
        }
        _tcEvaluatePeopleImage2.Controls.Add(_imgEvaluatePeople2);
        _trVerifyImage.Cells.Add(_tcEvaluatePeopleImage2);

        //绑定评估人名称到ｔａｂｌｅ
        TableCell _tcEvaluatePeople2 = new TableCell();
        Label _lblEvaluatePeople2 = new Label();
        _lblEvaluatePeople2.Text = _evaluatePeople2;
        _tcEvaluatePeople2.Controls.Add(_lblEvaluatePeople2);
        _trVerifyPeople.Cells.Add(_tcEvaluatePeople2);


        //创建二次评估人时间空格
        TableCell _tcEvaluateTime2 = new TableCell();
        trTime.Cells.Add(_tcEvaluateTime2);

        //创建二次评估人时间
        _tcEvaluateTime2 = new TableCell();
        Label _lblEvaluateTime2 = new Label();
        if (_systemLog.Rows.Count > 0)
        {
            if (_systemLog.Rows[_systemLog.Rows.Count - 1]["OperatorReMark"].ToString() == "评估完成")
            {
                _lblEvaluateTime2.Text = _systemLog.Rows[_systemLog.Rows.Count - 1]["TimeDate"].ToString().Replace(" ", "<br>");
            }
        }
        else
        {
            _lblEvaluateTime2.Text = "";
        }
        _tcEvaluateTime2.Controls.Add(_lblEvaluateTime2);
        trTime.Cells.Add(_tcEvaluateTime2);




        #endregion

        if (_trVerifyImage.Cells.Count == 2)
        {
            _trVerifyImage.Cells.RemoveAt(_trVerifyImage.Cells.Count - 1);
        }

    }
}